<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /disk1/DNNAcc/gemmlowp/test/test_fixedpoint.cc</title>
  <link rel="stylesheet" type="text/css" href="../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">disk1/DNNAcc/gemmlowp/test</a> - test_fixedpoint.cc<span style="font-size: 80%;"> (source / <a href="test_fixedpoint.cc.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">248</td>
            <td class="headerCovTableEntry">252</td>
            <td class="headerCovTableEntryHi">98.4 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-17 13:31:02</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">435</td>
            <td class="headerCovTableEntry">435</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : // Copyright 2016 The Gemmlowp Authors. All Rights Reserved.</a>
<span class="lineNum">       2 </span>            : //
<span class="lineNum">       3 </span>            : // Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<span class="lineNum">       4 </span>            : // you may not use this file except in compliance with the License.
<span class="lineNum">       5 </span>            : // You may obtain a copy of the License at
<span class="lineNum">       6 </span>            : //
<span class="lineNum">       7 </span>            : //     http://www.apache.org/licenses/LICENSE-2.0
<span class="lineNum">       8 </span>            : //
<span class="lineNum">       9 </span>            : // Unless required by applicable law or agreed to in writing, software
<span class="lineNum">      10 </span>            : // distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<span class="lineNum">      11 </span>            : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<span class="lineNum">      12 </span>            : // See the License for the specific language governing permissions and
<span class="lineNum">      13 </span>            : // limitations under the License.
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span>            : // test_fixedpoint.cc: unit tests covering the fixedpoint/ directory.
<span class="lineNum">      16 </span>            : 
<span class="lineNum">      17 </span>            : #define GEMMLOWP_ENABLE_FIXEDPOINT_CONSTANTS_CHECKS
<span class="lineNum">      18 </span>            : 
<span class="lineNum">      19 </span>            : #include &lt;algorithm&gt;
<span class="lineNum">      20 </span>            : #include &lt;cinttypes&gt;
<span class="lineNum">      21 </span>            : #include &lt;cmath&gt;
<span class="lineNum">      22 </span>            : #include &lt;cstdio&gt;
<span class="lineNum">      23 </span>            : #include &lt;random&gt;
<span class="lineNum">      24 </span>            : #include &lt;vector&gt;
<span class="lineNum">      25 </span>            : 
<span class="lineNum">      26 </span>            : #include &quot;../fixedpoint/fixedpoint.h&quot;
<span class="lineNum">      27 </span>            : #include &quot;test.h&quot;
<span class="lineNum">      28 </span>            : 
<span class="lineNum">      29 </span>            : namespace gemmlowp {
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span>            : namespace {
<a name="32"><span class="lineNum">      32 </span>            : </a>
<span class="lineNum">      33 </span>            : template &lt;typename T&gt;
<span class="lineNum">      34 </span><span class="lineCov">     171848 : T Load(const typename FixedPointRawTypeTraits&lt;T&gt;::ScalarRawType* src) {</span>
<span class="lineNum">      35 </span><span class="lineCov">     171848 :   return *src;</span>
<a name="36"><span class="lineNum">      36 </span>            : }</a>
<span class="lineNum">      37 </span>            : template &lt;typename T&gt;
<span class="lineNum">      38 </span><span class="lineCov">     171848 : void Store(typename FixedPointRawTypeTraits&lt;T&gt;::ScalarRawType* dst, T v) {</span>
<span class="lineNum">      39 </span><span class="lineCov">     171848 :   *dst = v;</span>
<span class="lineNum">      40 </span><span class="lineCov">     171848 : }</span>
<span class="lineNum">      41 </span>            : #ifdef GEMMLOWP_NEON
<span class="lineNum">      42 </span>            : template &lt;&gt;
<span class="lineNum">      43 </span>            : int32x4_t Load&lt;int32x4_t&gt;(const std::int32_t* src) {
<span class="lineNum">      44 </span>            :   return vld1q_s32(src);
<span class="lineNum">      45 </span>            : }
<span class="lineNum">      46 </span>            : template &lt;&gt;
<span class="lineNum">      47 </span>            : int16x8_t Load&lt;int16x8_t&gt;(const std::int16_t* src) {
<span class="lineNum">      48 </span>            :   return vld1q_s16(src);
<span class="lineNum">      49 </span>            : }
<span class="lineNum">      50 </span>            : template &lt;&gt;
<span class="lineNum">      51 </span>            : void Store&lt;int32x4_t&gt;(std::int32_t* dst, int32x4_t v) {
<span class="lineNum">      52 </span>            :   vst1q_s32(dst, v);
<span class="lineNum">      53 </span>            : }
<span class="lineNum">      54 </span>            : template &lt;&gt;
<span class="lineNum">      55 </span>            : void Store&lt;int16x8_t&gt;(std::int16_t* dst, int16x8_t v) {
<span class="lineNum">      56 </span>            :   vst1q_s16(dst, v);
<span class="lineNum">      57 </span>            : }
<span class="lineNum">      58 </span>            : #endif
<span class="lineNum">      59 </span>            : #ifdef GEMMLOWP_SSE4
<span class="lineNum">      60 </span>            : template &lt;&gt;
<span class="lineNum">      61 </span>            : __m128i Load&lt;__m128i&gt;(const std::int32_t* src) {
<span class="lineNum">      62 </span>            :   return _mm_loadu_si128(reinterpret_cast&lt;const __m128i*&gt;(src));
<span class="lineNum">      63 </span>            : }
<span class="lineNum">      64 </span>            : template &lt;&gt;
<span class="lineNum">      65 </span>            : void Store&lt;__m128i&gt;(std::int32_t* dst, __m128i v) {
<span class="lineNum">      66 </span>            :   _mm_storeu_si128(reinterpret_cast&lt;__m128i*&gt;(dst), v);
<span class="lineNum">      67 </span>            : }
<span class="lineNum">      68 </span>            : template &lt;&gt;
<span class="lineNum">      69 </span>            : int16x8_m128i Load&lt;int16x8_m128i&gt;(const std::int16_t* src) {
<span class="lineNum">      70 </span>            :   return to_int16x8_m128i(
<span class="lineNum">      71 </span>            :       _mm_loadu_si128(reinterpret_cast&lt;const __m128i*&gt;(src)));
<span class="lineNum">      72 </span>            : }
<span class="lineNum">      73 </span>            : template &lt;&gt;
<span class="lineNum">      74 </span>            : void Store&lt;int16x8_m128i&gt;(std::int16_t* dst, int16x8_m128i v) {
<span class="lineNum">      75 </span>            :   _mm_storeu_si128(reinterpret_cast&lt;__m128i*&gt;(dst), v.v);
<span class="lineNum">      76 </span>            : }
<span class="lineNum">      77 </span>            : #endif
<span class="lineNum">      78 </span>            : #ifdef GEMMLOWP_MSA
<span class="lineNum">      79 </span>            : template &lt;&gt;
<span class="lineNum">      80 </span>            : v4i32 Load&lt;v4i32&gt;(const std::int32_t* src) {
<span class="lineNum">      81 </span>            :   return __builtin_msa_ld_w(const_cast&lt;std::int32_t*&gt;(src), 0);
<span class="lineNum">      82 </span>            : }
<span class="lineNum">      83 </span>            : template &lt;&gt;
<span class="lineNum">      84 </span>            : v8i16 Load&lt;v8i16&gt;(const std::int16_t* src) {
<span class="lineNum">      85 </span>            :   return __builtin_msa_ld_h(const_cast&lt;std::int16_t*&gt;(src), 0);
<span class="lineNum">      86 </span>            : }
<span class="lineNum">      87 </span>            : template &lt;&gt;
<span class="lineNum">      88 </span>            : void Store&lt;v4i32&gt;(std::int32_t* dst, v4i32 v) {
<span class="lineNum">      89 </span>            :   __builtin_msa_st_w(v, dst, 0);
<span class="lineNum">      90 </span>            : }
<span class="lineNum">      91 </span>            : template &lt;&gt;
<span class="lineNum">      92 </span>            : void Store&lt;v8i16&gt;(std::int16_t* dst, v8i16 v) {
<span class="lineNum">      93 </span>            :   __builtin_msa_st_h(v, dst, 0);
<span class="lineNum">      94 </span>            : }
<span class="lineNum">      95 </span>            : #endif
<span class="lineNum">      96 </span>            : 
<span class="lineNum">      97 </span>            : #ifdef GEMMLOWP_AVX2
<span class="lineNum">      98 </span>            : template &lt;&gt;
<span class="lineNum">      99 </span>            : __m256i Load&lt;__m256i&gt;(const std::int32_t* src) {
<span class="lineNum">     100 </span>            :   return _mm256_loadu_si256(reinterpret_cast&lt;const __m256i*&gt;(src));
<span class="lineNum">     101 </span>            : }
<span class="lineNum">     102 </span>            : 
<span class="lineNum">     103 </span>            : template &lt;&gt;
<span class="lineNum">     104 </span>            : int16x16_m256i Load&lt;int16x16_m256i&gt;(const std::int16_t* src) {
<span class="lineNum">     105 </span>            :   return to_int16x16_m256i(
<span class="lineNum">     106 </span>            :       _mm256_loadu_si256(reinterpret_cast&lt;const __m256i*&gt;(src)));
<span class="lineNum">     107 </span>            : }
<span class="lineNum">     108 </span>            : 
<span class="lineNum">     109 </span>            : template &lt;&gt;
<span class="lineNum">     110 </span>            : void Store&lt;__m256i&gt;(std::int32_t* dst, __m256i v) {
<span class="lineNum">     111 </span>            :   _mm256_storeu_si256(reinterpret_cast&lt;__m256i*&gt;(dst), v);
<span class="lineNum">     112 </span>            : }
<span class="lineNum">     113 </span>            : 
<span class="lineNum">     114 </span>            : template &lt;&gt;
<span class="lineNum">     115 </span>            : void Store&lt;int16x16_m256i&gt;(std::int16_t* dst, int16x16_m256i v) {
<span class="lineNum">     116 </span>            :   _mm256_storeu_si256(reinterpret_cast&lt;__m256i*&gt;(dst), v.v);
<span class="lineNum">     117 </span>            : }
<span class="lineNum">     118 </span>            : #endif
<span class="lineNum">     119 </span>            : 
<span class="lineNum">     120 </span>            : template &lt;typename tSimdType&gt;
<span class="lineNum">     121 </span>            : class TestFixedPoint {
<span class="lineNum">     122 </span>            :  public:
<span class="lineNum">     123 </span>            :   using SimdType = tSimdType;
<span class="lineNum">     124 </span>            :   using SimdTypeTraits = FixedPointRawTypeTraits&lt;SimdType&gt;;
<span class="lineNum">     125 </span>            :   using ScalarType = typename SimdTypeTraits::ScalarRawType;
<span class="lineNum">     126 </span>            :   static constexpr int kSimdLanes = SimdTypeTraits::kLanes;
<span class="lineNum">     127 </span>            :   static constexpr int kScalarTypeBits = 8 * sizeof(ScalarType);
<span class="lineNum">     128 </span>            : 
<span class="lineNum">     129 </span>            :   // Explanation of UnaryOpBase, its *Op subclasses below, and TestUnaryOp:
<span class="lineNum">     130 </span>            :   // Most (though not all) of the fixedpoint functionality being tested
<span class="lineNum">     131 </span>            :   // consists of functions taking one fixedpoint value and returning one
<span class="lineNum">     132 </span>            :   // fixedpoint value, e.g. &quot;exp&quot; or &quot;tanh&quot;. We call them &quot;unary operators&quot;.
<span class="lineNum">     133 </span>            :   // We factor a lot of testing boilerplate into a common TestUnaryOp function
<span class="lineNum">     134 </span>            :   // taking a &quot;unary op&quot; object that fully describes the function to be tested.
<span class="lineNum">     135 </span>            :   // These objects inherit UnaryOpBase mostly as a means to share some default
<span class="lineNum">     136 </span>            :   // values for some properties.
<span class="lineNum">     137 </span>            :   //
<span class="lineNum">     138 </span>            :   // An important design element here is that the fixed-point values are passed
<span class="lineNum">     139 </span>            :   // around as raw integers (e.g. int32_t or SIMD types such as int32x4_t), not
<span class="lineNum">     140 </span>            :   // as higher-level FixedPoint objects. The motivation for this design is 1) to
<span class="lineNum">     141 </span>            :   // avoid having to templatize everything in the tIntegerBits parameter of
<span class="lineNum">     142 </span>            :   // class FixedPoint, and 2) to allow directly testing low-level functions
<span class="lineNum">     143 </span>            :   // operating on raw types (e.g. RoundingDivideByPOT) without needlessly
<a name="144"><span class="lineNum">     144 </span>            :   // requiring</a>
<span class="lineNum">     145 </span>            :   // wrapping raw values in FixedPoint objects.
<span class="lineNum">     146 </span><span class="lineCov">         48 :   class UnaryOpBase {</span>
<span class="lineNum">     147 </span>            :    public:
<a name="148"><span class="lineNum">     148 </span>            :     // Min bound of the input range of this op. For example, an op only handling</a>
<span class="lineNum">     149 </span>            :     // nonnegative values would return 0.
<span class="lineNum">     150 </span><span class="lineCov">     164432 :     ScalarType MinInput() const {</span>
<span class="lineNum">     151 </span><span class="lineCov">     164432 :       return std::numeric_limits&lt;ScalarType&gt;::min();</span>
<span class="lineNum">     152 </span>            :     }
<a name="153"><span class="lineNum">     153 </span>            :     // Max bound of the input range of this op. For example, an op only handling</a>
<span class="lineNum">     154 </span>            :     // nonpositive values would return 0.
<span class="lineNum">     155 </span><span class="lineCov">     152072 :     ScalarType MaxInput() const {</span>
<span class="lineNum">     156 </span><span class="lineCov">     152072 :       return std::numeric_limits&lt;ScalarType&gt;::max();</span>
<span class="lineNum">     157 </span>            :     }
<span class="lineNum">     158 </span>            :     // Tolerated difference between actual and reference ScalarType values.
<span class="lineNum">     159 </span>            :     // Note that the corresponding real-numbers tolerance depends on the number
<span class="lineNum">     160 </span>            :     // of integer bits of the fixed-point representation of the results of this
<span class="lineNum">     161 </span>            :     // op.
<span class="lineNum">     162 </span>            :     // For example, for an op returning fixed-point values with 0 integer bits,
<a name="163"><span class="lineNum">     163 </span>            :     // the correspondence between real-number values and raw values is</a>
<span class="lineNum">     164 </span>            :     // real_number = (2^31) * raw_value.
<span class="lineNum">     165 </span><span class="lineCov">     225040 :     ScalarType Tolerance() const { return 0; }</span>
<span class="lineNum">     166 </span>            :   };
<span class="lineNum">     167 </span>            : 
<span class="lineNum">     168 </span>            :   // Op wrapping RoundingDivideByPOT
<a name="169"><span class="lineNum">     169 </span>            :   class RoundingDivideByPOTOp final : public UnaryOpBase {</a>
<a name="170"><span class="lineNum">     170 </span>            :    public:</a>
<span class="lineNum">     171 </span><span class="lineCov">         48 :     RoundingDivideByPOTOp(int exponent) : exponent_(exponent) {}</span>
<span class="lineNum">     172 </span><span class="lineCov">      60608 :     ScalarType ReferenceOp(ScalarType x) const {</span>
<span class="lineNum">     173 </span><span class="lineCov">      60608 :       const double d = static_cast&lt;double&gt;(x) / (1ll &lt;&lt; exponent_);</span>
<span class="lineNum">     174 </span><span class="lineCov">      60608 :       return static_cast&lt;ScalarType&gt;(std::round(d));</span>
<a name="175"><span class="lineNum">     175 </span>            :     }</a>
<span class="lineNum">     176 </span>            :     template &lt;typename RawType&gt;
<span class="lineNum">     177 </span><span class="lineCov">     121216 :     RawType Op(RawType x) const {</span>
<span class="lineNum">     178 </span><span class="lineCov">     121216 :       return RoundingDivideByPOT(x, exponent_);</span>
<span class="lineNum">     179 </span>            :     }
<span class="lineNum">     180 </span>            : 
<span class="lineNum">     181 </span>            :    private:
<span class="lineNum">     182 </span>            :     const int exponent_;
<span class="lineNum">     183 </span>            :   };
<span class="lineNum">     184 </span>            : 
<span class="lineNum">     185 </span>            :   // Op wrapping SaturatingRoundingMultiplyByPOT
<span class="lineNum">     186 </span>            :   template &lt;int tExponent&gt;
<a name="187"><span class="lineNum">     187 </span>            :   class SaturatingRoundingMultiplyByPOTOp final : public UnaryOpBase {</a>
<span class="lineNum">     188 </span>            :    public:
<span class="lineNum">     189 </span><span class="lineCov">      51912 :     ScalarType ReferenceOp(ScalarType x) const {</span>
<span class="lineNum">     190 </span><span class="lineCov">      51912 :       const double d = static_cast&lt;double&gt;(x) * std::pow(2., tExponent);</span>
<span class="lineNum">     191 </span><span class="lineCov">      51912 :       const double clamp_min = std::numeric_limits&lt;ScalarType&gt;::min();</span>
<span class="lineNum">     192 </span><span class="lineCov">      51912 :       const double clamp_max = std::numeric_limits&lt;ScalarType&gt;::max();</span>
<span class="lineNum">     193 </span><span class="lineCov">      51912 :       const double clamped = std::min(clamp_max, std::max(clamp_min, d));</span>
<span class="lineNum">     194 </span><span class="lineCov">      51912 :       return static_cast&lt;ScalarType&gt;(std::round(clamped));</span>
<a name="195"><span class="lineNum">     195 </span>            :     }</a>
<span class="lineNum">     196 </span>            :     template &lt;typename RawType&gt;
<span class="lineNum">     197 </span><span class="lineCov">     103824 :     RawType Op(RawType x) const {</span>
<span class="lineNum">     198 </span><span class="lineCov">     103824 :       return SaturatingRoundingMultiplyByPOT&lt;tExponent&gt;(x);</span>
<span class="lineNum">     199 </span>            :     }
<span class="lineNum">     200 </span>            :   };
<span class="lineNum">     201 </span>            : 
<span class="lineNum">     202 </span>            :   // Op wrapping exp_on_interval_between_negative_one_quarter_and_0_excl
<span class="lineNum">     203 </span>            :   class ExpOnIntervalBetweenNegativeOneQuarterAnd0ExclOp final
<a name="204"><span class="lineNum">     204 </span>            :       : public UnaryOpBase {</a>
<a name="205"><span class="lineNum">     205 </span>            :    public:</a>
<a name="206"><span class="lineNum">     206 </span><span class="lineCov">       2472 :     ScalarType MinInput() const { return -(1 &lt;&lt; (kScalarTypeBits - 3)); }</span></a>
<a name="207"><span class="lineNum">     207 </span><span class="lineCov">       2472 :     ScalarType MaxInput() const { return 0; }</span></a>
<span class="lineNum">     208 </span><span class="lineCov">       4944 :     ScalarType Tolerance() const { return kScalarTypeBits == 32 ? 500 : 1; }</span>
<span class="lineNum">     209 </span><span class="lineCov">       2472 :     ScalarType ReferenceOp(ScalarType x) const {</span>
<span class="lineNum">     210 </span>            :       using F = FixedPoint&lt;ScalarType, 0&gt;;
<span class="lineNum">     211 </span><span class="lineCov">       2472 :       const double d = ToDouble(F::FromRaw(x));</span>
<span class="lineNum">     212 </span><span class="lineCov">       2472 :       const double e = std::exp(d);</span>
<span class="lineNum">     213 </span><span class="lineCov">       2472 :       return F::FromDouble(e).raw();</span>
<a name="214"><span class="lineNum">     214 </span>            :     }</a>
<span class="lineNum">     215 </span>            :     template &lt;typename RawType&gt;
<span class="lineNum">     216 </span><span class="lineCov">       4944 :     RawType Op(RawType x) const {</span>
<span class="lineNum">     217 </span>            :       using F = FixedPoint&lt;RawType, 0&gt;;
<span class="lineNum">     218 </span><span class="lineCov">       4944 :       const F f = F::FromRaw(x);</span>
<span class="lineNum">     219 </span><span class="lineCov">       4944 :       const F e = exp_on_interval_between_negative_one_quarter_and_0_excl(f);</span>
<span class="lineNum">     220 </span><span class="lineCov">       4944 :       return e.raw();</span>
<span class="lineNum">     221 </span>            :     }
<span class="lineNum">     222 </span>            :   };
<span class="lineNum">     223 </span>            : 
<span class="lineNum">     224 </span>            :   // Op wrapping exp_on_negative_values
<span class="lineNum">     225 </span>            :   template &lt;int tIntegerBits&gt;
<a name="226"><span class="lineNum">     226 </span>            :   class ExpOnNegativeValuesOp final : public UnaryOpBase {</a>
<a name="227"><span class="lineNum">     227 </span>            :    public:</a>
<a name="228"><span class="lineNum">     228 </span><span class="lineCov">      17304 :     ScalarType MaxInput() const { return 0; }</span></a>
<span class="lineNum">     229 </span><span class="lineCov">      34608 :     ScalarType Tolerance() const { return kScalarTypeBits == 32 ? 500 : 2; }</span>
<span class="lineNum">     230 </span><span class="lineCov">      17304 :     ScalarType ReferenceOp(ScalarType x) const {</span>
<span class="lineNum">     231 </span>            :       using F = FixedPoint&lt;ScalarType, tIntegerBits&gt;;
<span class="lineNum">     232 </span>            :       using F0 = FixedPoint&lt;ScalarType, 0&gt;;
<span class="lineNum">     233 </span><span class="lineCov">      17304 :       const double d = ToDouble(F::FromRaw(x));</span>
<span class="lineNum">     234 </span><span class="lineCov">      17304 :       const double e = std::exp(d);</span>
<span class="lineNum">     235 </span><span class="lineCov">      17304 :       return F0::FromDouble(e).raw();</span>
<a name="236"><span class="lineNum">     236 </span>            :     }</a>
<span class="lineNum">     237 </span>            :     template &lt;typename RawType&gt;
<span class="lineNum">     238 </span><span class="lineCov">      34608 :     RawType Op(RawType x) const {</span>
<span class="lineNum">     239 </span>            :       using F = FixedPoint&lt;RawType, tIntegerBits&gt;;
<span class="lineNum">     240 </span><span class="lineCov">      34608 :       const F f = F::FromRaw(x);</span>
<span class="lineNum">     241 </span><span class="lineCov">      34608 :       return exp_on_negative_values(f).raw();</span>
<span class="lineNum">     242 </span>            :     }
<span class="lineNum">     243 </span>            :   };
<span class="lineNum">     244 </span>            : 
<span class="lineNum">     245 </span>            :   // Op wrapping one_minus_x_over_one_plus_x_for_x_in_0_1
<a name="246"><span class="lineNum">     246 </span>            :   class OneMinusXOverOnePlusXForXIn01Op final : public UnaryOpBase {</a>
<a name="247"><span class="lineNum">     247 </span>            :    public:</a>
<a name="248"><span class="lineNum">     248 </span><span class="lineCov">       2472 :     ScalarType MinInput() const { return 0; }</span></a>
<span class="lineNum">     249 </span><span class="lineCov">       4944 :     ScalarType Tolerance() const { return kScalarTypeBits == 32 ? 12 : 11; }</span>
<span class="lineNum">     250 </span><span class="lineCov">       2472 :     ScalarType ReferenceOp(ScalarType x) const {</span>
<span class="lineNum">     251 </span>            :       using F = FixedPoint&lt;ScalarType, 0&gt;;
<span class="lineNum">     252 </span><span class="lineCov">       2472 :       const double d = ToDouble(F::FromRaw(x));</span>
<span class="lineNum">     253 </span><span class="lineCov">       2472 :       const double e = (1 - d) / (1 + d);</span>
<span class="lineNum">     254 </span><span class="lineCov">       2472 :       return F::FromDouble(e).raw();</span>
<a name="255"><span class="lineNum">     255 </span>            :     }</a>
<span class="lineNum">     256 </span>            :     template &lt;typename RawType&gt;
<span class="lineNum">     257 </span><span class="lineCov">       4944 :     RawType Op(RawType x) const {</span>
<span class="lineNum">     258 </span>            :       using F = FixedPoint&lt;RawType, 0&gt;;
<span class="lineNum">     259 </span><span class="lineCov">       4944 :       const F f = F::FromRaw(x);</span>
<span class="lineNum">     260 </span><span class="lineCov">       4944 :       return one_minus_x_over_one_plus_x_for_x_in_0_1(f).raw();</span>
<span class="lineNum">     261 </span>            :     }
<span class="lineNum">     262 </span>            :   };
<span class="lineNum">     263 </span>            : 
<span class="lineNum">     264 </span>            :   // Op wrapping tanh
<span class="lineNum">     265 </span>            :   template &lt;int tIntegerBits&gt;
<a name="266"><span class="lineNum">     266 </span>            :   class TanhOp final : public UnaryOpBase {</a>
<a name="267"><span class="lineNum">     267 </span>            :    public:</a>
<span class="lineNum">     268 </span><span class="lineCov">      34608 :     ScalarType Tolerance() const { return kScalarTypeBits == 32 ? 310 : 12; }</span>
<span class="lineNum">     269 </span><span class="lineCov">      17304 :     ScalarType ReferenceOp(ScalarType x) const {</span>
<span class="lineNum">     270 </span>            :       using F = FixedPoint&lt;ScalarType, tIntegerBits&gt;;
<span class="lineNum">     271 </span>            :       using F0 = FixedPoint&lt;ScalarType, 0&gt;;
<span class="lineNum">     272 </span><span class="lineCov">      17304 :       const double d = ToDouble(F::FromRaw(x));</span>
<span class="lineNum">     273 </span><span class="lineCov">      17304 :       const double e = std::tanh(d);</span>
<span class="lineNum">     274 </span><span class="lineCov">      17304 :       return F0::FromDouble(e).raw();</span>
<a name="275"><span class="lineNum">     275 </span>            :     }</a>
<span class="lineNum">     276 </span>            :     template &lt;typename RawType&gt;
<span class="lineNum">     277 </span><span class="lineCov">      34608 :     RawType Op(RawType x) const {</span>
<span class="lineNum">     278 </span>            :       using F = FixedPoint&lt;RawType, tIntegerBits&gt;;
<span class="lineNum">     279 </span><span class="lineCov">      34608 :       const F f = F::FromRaw(x);</span>
<span class="lineNum">     280 </span><span class="lineCov">      34608 :       return tanh(f).raw();</span>
<span class="lineNum">     281 </span>            :     }
<span class="lineNum">     282 </span>            :   };
<span class="lineNum">     283 </span>            : 
<span class="lineNum">     284 </span>            :   // Op wrapping one_over_one_plus_x_for_x_in_0_1
<a name="285"><span class="lineNum">     285 </span>            :   class OneOverOnePlusXForXIn01Op final : public UnaryOpBase {</a>
<a name="286"><span class="lineNum">     286 </span>            :    public:</a>
<a name="287"><span class="lineNum">     287 </span><span class="lineCov">       2472 :     ScalarType MinInput() const { return 0; }</span></a>
<span class="lineNum">     288 </span><span class="lineCov">       4944 :     ScalarType Tolerance() const { return kScalarTypeBits == 32 ? 6 : 5; }</span>
<span class="lineNum">     289 </span><span class="lineCov">       2472 :     ScalarType ReferenceOp(ScalarType x) const {</span>
<span class="lineNum">     290 </span>            :       using F = FixedPoint&lt;ScalarType, 0&gt;;
<span class="lineNum">     291 </span><span class="lineCov">       2472 :       const double d = ToDouble(F::FromRaw(x));</span>
<span class="lineNum">     292 </span><span class="lineCov">       2472 :       const double e = 1 / (1 + d);</span>
<span class="lineNum">     293 </span><span class="lineCov">       2472 :       return F::FromDouble(e).raw();</span>
<a name="294"><span class="lineNum">     294 </span>            :     }</a>
<span class="lineNum">     295 </span>            :     template &lt;typename RawType&gt;
<span class="lineNum">     296 </span><span class="lineCov">       4944 :     RawType Op(RawType x) const {</span>
<span class="lineNum">     297 </span>            :       using F = FixedPoint&lt;RawType, 0&gt;;
<span class="lineNum">     298 </span><span class="lineCov">       4944 :       const F f = F::FromRaw(x);</span>
<span class="lineNum">     299 </span><span class="lineCov">       4944 :       return one_over_one_plus_x_for_x_in_0_1(f).raw();</span>
<span class="lineNum">     300 </span>            :     }
<span class="lineNum">     301 </span>            :   };
<span class="lineNum">     302 </span>            : 
<span class="lineNum">     303 </span>            :   // Op wrapping logistic
<span class="lineNum">     304 </span>            :   template &lt;int tIntegerBits&gt;
<a name="305"><span class="lineNum">     305 </span>            :   class LogisticOp final : public UnaryOpBase {</a>
<a name="306"><span class="lineNum">     306 </span>            :    public:</a>
<span class="lineNum">     307 </span><span class="lineCov">      34608 :     ScalarType Tolerance() const { return kScalarTypeBits == 32 ? 155 : 6; }</span>
<span class="lineNum">     308 </span><span class="lineCov">      17304 :     ScalarType ReferenceOp(ScalarType x) const {</span>
<span class="lineNum">     309 </span>            :       using F = FixedPoint&lt;ScalarType, tIntegerBits&gt;;
<span class="lineNum">     310 </span>            :       using F0 = FixedPoint&lt;ScalarType, 0&gt;;
<span class="lineNum">     311 </span><span class="lineCov">      17304 :       const double d = ToDouble(F::FromRaw(x));</span>
<span class="lineNum">     312 </span><span class="lineCov">      17304 :       const double e = 1 / (1 + std::exp(-d));</span>
<span class="lineNum">     313 </span><span class="lineCov">      17304 :       return F0::FromDouble(e).raw();</span>
<a name="314"><span class="lineNum">     314 </span>            :     }</a>
<span class="lineNum">     315 </span>            :     template &lt;typename RawType&gt;
<span class="lineNum">     316 </span><span class="lineCov">      34608 :     RawType Op(RawType x) const {</span>
<span class="lineNum">     317 </span>            :       using F = FixedPoint&lt;RawType, tIntegerBits&gt;;
<span class="lineNum">     318 </span><span class="lineCov">      34608 :       const F f = F::FromRaw(x);</span>
<span class="lineNum">     319 </span><span class="lineCov">      34608 :       return logistic(f).raw();</span>
<span class="lineNum">     320 </span>            :     }
<span class="lineNum">     321 </span>            :   };
<span class="lineNum">     322 </span>            : 
<a name="323"><span class="lineNum">     323 </span>            :   // Tests a given op, on a given list of int32 input values.</a>
<span class="lineNum">     324 </span>            :   template &lt;typename tUnaryOpType&gt;
<span class="lineNum">     325 </span><span class="lineCov">        138 :   void TestUnaryOp(const tUnaryOpType&amp; unary_op,</span>
<span class="lineNum">     326 </span>            :                    const std::vector&lt;ScalarType&gt;&amp; testvals) {
<span class="lineNum">     327 </span><span class="lineCov">        138 :     Check(0 == (testvals.size() % kSimdLanes));</span>
<span class="lineNum">     328 </span><span class="lineCov">     171986 :     for (std::size_t i = 0; i &lt; testvals.size(); i += kSimdLanes) {</span>
<span class="lineNum">     329 </span>            :       // First, clamp input values accoding to the MinInput() and MaxInput()
<span class="lineNum">     330 </span>            :       // bounds returned by the op.
<span class="lineNum">     331 </span><span class="lineCov">     171848 :       ScalarType input[kSimdLanes] = {0};</span>
<span class="lineNum">     332 </span><span class="lineCov">     343696 :       for (std::size_t j = 0; j &lt; kSimdLanes; j++) {</span>
<span class="lineNum">     333 </span><span class="lineCov">     171848 :         const ScalarType raw_input = testvals[i + j];</span>
<span class="lineNum">     334 </span><span class="lineCov">     171848 :         input[j] = std::min(unary_op.MaxInput(),</span>
<span class="lineNum">     335 </span><span class="lineCov">     343696 :                             std::max(unary_op.MinInput(), raw_input));</span>
<span class="lineNum">     336 </span>            :       }
<span class="lineNum">     337 </span>            :       // Compute reference results and check that the actual results on
<span class="lineNum">     338 </span>            :       // scalar inputs agree with them, to the Tolerance() returned by the op.
<span class="lineNum">     339 </span><span class="lineCov">     171848 :       ScalarType reference[kSimdLanes] = {0};</span>
<span class="lineNum">     340 </span><span class="lineCov">     171848 :       ScalarType actual_scalar[kSimdLanes] = {0};</span>
<span class="lineNum">     341 </span><span class="lineCov">     343696 :       for (std::size_t j = 0; j &lt; kSimdLanes; j++) {</span>
<span class="lineNum">     342 </span><span class="lineCov">     171848 :         reference[j] = unary_op.ReferenceOp(input[j]);</span>
<span class="lineNum">     343 </span><span class="lineCov">     171848 :         actual_scalar[j] = unary_op.Op(input[j]);</span>
<span class="lineNum">     344 </span><span class="lineCov">     171848 :         const std::int64_t diff = static_cast&lt;std::int64_t&gt;(actual_scalar[j]) -</span>
<span class="lineNum">     345 </span><span class="lineCov">     171848 :                                   static_cast&lt;std::int64_t&gt;(reference[j]);</span>
<span class="lineNum">     346 </span><span class="lineCov">     171848 :         if (std::abs(diff) &gt; unary_op.Tolerance()) {</span>
<span class="lineNum">     347 </span><span class="lineNoCov">          0 :           fprintf(stderr, &quot;abs(diff) (%&quot; PRId64 &quot;) &gt; tolerance (%d)\n&quot;, diff,</span>
<span class="lineNum">     348 </span>            :                   unary_op.Tolerance());
<span class="lineNum">     349 </span>            :         }
<span class="lineNum">     350 </span><span class="lineCov">     171848 :         Check(std::abs(diff) &lt;= unary_op.Tolerance());</span>
<span class="lineNum">     351 </span>            :       }
<span class="lineNum">     352 </span>            :       // Check that the actual results on SIMD inputs agree *exactly* with the
<span class="lineNum">     353 </span>            :       // actual results on scalar inputs. I.e. SIMD must make absolutely no
<span class="lineNum">     354 </span>            :       // difference
<span class="lineNum">     355 </span>            :       // to the results, regardless of the fact that both scalar and SIMD
<span class="lineNum">     356 </span>            :       // results may differ from the reference results.
<span class="lineNum">     357 </span><span class="lineCov">     171848 :       ScalarType actual_simd[kSimdLanes] = {0};</span>
<span class="lineNum">     358 </span><span class="lineCov">     171848 :       Store&lt;SimdType&gt;(actual_simd, unary_op.Op(Load&lt;SimdType&gt;(input)));</span>
<span class="lineNum">     359 </span><span class="lineCov">     343696 :       for (std::size_t j = 0; j &lt; kSimdLanes; j++) {</span>
<span class="lineNum">     360 </span><span class="lineCov">     171848 :         if (actual_simd[j] != actual_scalar[j]) {</span>
<span class="lineNum">     361 </span><span class="lineNoCov">          0 :           fprintf(stderr, &quot;SIMD (%d) != scalar (%d)\n&quot;, actual_simd[j],</span>
<span class="lineNum">     362 </span><span class="lineNoCov">          0 :                   actual_scalar[j]);</span>
<span class="lineNum">     363 </span>            :         }
<span class="lineNum">     364 </span><span class="lineCov">     171848 :         Check(actual_simd[j] == actual_scalar[j]);</span>
<span class="lineNum">     365 </span>            :       }
<span class="lineNum">     366 </span>            :     }
<span class="lineNum">     367 </span><span class="lineCov">        138 :   }</span>
<a name="368"><span class="lineNum">     368 </span>            : </a>
<span class="lineNum">     369 </span>            :   template &lt;int tIntegerBits&gt;
<span class="lineNum">     370 </span><span class="lineCov">       2472 :   void test_convert(FixedPoint&lt;ScalarType, tIntegerBits&gt; x) {</span>
<span class="lineNum">     371 </span>            :     typedef FixedPoint&lt;ScalarType, tIntegerBits&gt; F;
<span class="lineNum">     372 </span><span class="lineCov">       2472 :     F y = F::FromDouble(ToDouble(x));</span>
<span class="lineNum">     373 </span><span class="lineCov">       2472 :     Check(y == x);</span>
<span class="lineNum">     374 </span><span class="lineCov">       2472 :   }</span>
<a name="375"><span class="lineNum">     375 </span>            : </a>
<span class="lineNum">     376 </span>            :   template &lt;int tIntegerBits_a, int tIntegerBits_b&gt;
<span class="lineNum">     377 </span><span class="lineCov">      17304 :   void test_Rescale(FixedPoint&lt;ScalarType, tIntegerBits_a&gt; a) {</span>
<span class="lineNum">     378 </span><span class="lineCov">      17304 :     FixedPoint&lt;ScalarType, tIntegerBits_b&gt; actual = Rescale&lt;tIntegerBits_b&gt;(a);</span>
<span class="lineNum">     379 </span>            :     FixedPoint&lt;ScalarType, tIntegerBits_b&gt; expected =
<span class="lineNum">     380 </span><span class="lineCov">      17304 :         FixedPoint&lt;ScalarType, tIntegerBits_b&gt;::FromDouble(ToDouble(a));</span>
<span class="lineNum">     381 </span><span class="lineCov">      17304 :     Check(actual == expected);</span>
<span class="lineNum">     382 </span><span class="lineCov">      17304 :   }</span>
<a name="383"><span class="lineNum">     383 </span>            : </a>
<span class="lineNum">     384 </span>            :   template &lt;int tIntegerBits_a, int tIntegerBits_b&gt;
<span class="lineNum">     385 </span><span class="lineCov">         14 :   void test_Rescale(const std::vector&lt;ScalarType&gt;&amp; testvals) {</span>
<span class="lineNum">     386 </span><span class="lineCov">      17318 :     for (auto a : testvals) {</span>
<span class="lineNum">     387 </span>            :       FixedPoint&lt;ScalarType, tIntegerBits_a&gt; aq;
<span class="lineNum">     388 </span><span class="lineCov">      17304 :       aq.raw() = a;</span>
<span class="lineNum">     389 </span><span class="lineCov">      17304 :       test_Rescale&lt;tIntegerBits_a, tIntegerBits_b&gt;(aq);</span>
<span class="lineNum">     390 </span>            :     }
<span class="lineNum">     391 </span><span class="lineCov">         14 :   }</span>
<a name="392"><span class="lineNum">     392 </span>            : </a>
<span class="lineNum">     393 </span>            :   template &lt;int tIntegerBits_a, int tIntegerBits_b&gt;
<span class="lineNum">     394 </span><span class="lineCov">   24545536 :   void test_mul(FixedPoint&lt;ScalarType, tIntegerBits_a&gt; a,</span>
<span class="lineNum">     395 </span>            :                 FixedPoint&lt;ScalarType, tIntegerBits_b&gt; b) {
<span class="lineNum">     396 </span>            :     static const int ProductIntegerBits = tIntegerBits_a + tIntegerBits_b;
<span class="lineNum">     397 </span>            :     using ProductFixedPoint = FixedPoint&lt;ScalarType, ProductIntegerBits&gt;;
<span class="lineNum">     398 </span>            :     ProductFixedPoint ab;
<span class="lineNum">     399 </span><span class="lineCov">   24545536 :     ab = a * b;</span>
<span class="lineNum">     400 </span><span class="lineCov">   24545536 :     double a_double = ToDouble(a);</span>
<span class="lineNum">     401 </span><span class="lineCov">   24545536 :     double b_double = ToDouble(b);</span>
<span class="lineNum">     402 </span><span class="lineCov">   24545536 :     double ab_double = a_double * b_double;</span>
<span class="lineNum">     403 </span><span class="lineCov">   24545536 :     ProductFixedPoint expected = ProductFixedPoint::FromDouble(ab_double);</span>
<span class="lineNum">     404 </span><span class="lineCov">   24545536 :     std::int64_t diff = std::int64_t(ab.raw()) - std::int64_t(expected.raw());</span>
<span class="lineNum">     405 </span><span class="lineCov">   24545536 :     Check(std::abs(diff) &lt;= 1);</span>
<span class="lineNum">     406 </span><span class="lineCov">   24545536 :   }</span>
<a name="407"><span class="lineNum">     407 </span>            : </a>
<span class="lineNum">     408 </span>            :   template &lt;int tIntegerBits_a, int tIntegerBits_b&gt;
<span class="lineNum">     409 </span><span class="lineCov">         16 :   void test_mul(const std::vector&lt;ScalarType&gt;&amp; testvals) {</span>
<span class="lineNum">     410 </span><span class="lineCov">      19792 :     for (auto a : testvals) {</span>
<span class="lineNum">     411 </span><span class="lineCov">   24565312 :       for (auto b : testvals) {</span>
<span class="lineNum">     412 </span>            :         FixedPoint&lt;ScalarType, tIntegerBits_a&gt; aq;
<span class="lineNum">     413 </span>            :         FixedPoint&lt;ScalarType, tIntegerBits_b&gt; bq;
<span class="lineNum">     414 </span><span class="lineCov">   24545536 :         aq.raw() = a;</span>
<span class="lineNum">     415 </span><span class="lineCov">   24545536 :         bq.raw() = b;</span>
<span class="lineNum">     416 </span><span class="lineCov">   24545536 :         test_mul(aq, bq);</span>
<span class="lineNum">     417 </span>            :       }
<span class="lineNum">     418 </span>            :     }
<span class="lineNum">     419 </span><span class="lineCov">         16 :   }</span>
<a name="420"><span class="lineNum">     420 </span>            : </a>
<span class="lineNum">     421 </span>            :   template &lt;int tExponent, int tIntegerBits_a&gt;
<span class="lineNum">     422 </span><span class="lineCov">      14832 :   void test_ExactMulByPot(FixedPoint&lt;ScalarType, tIntegerBits_a&gt; a) {</span>
<span class="lineNum">     423 </span><span class="lineCov">      14832 :     double x = ToDouble(a) * std::pow(2.0, tExponent);</span>
<span class="lineNum">     424 </span><span class="lineCov">      14832 :     double y = ToDouble(ExactMulByPot&lt;tExponent&gt;(a));</span>
<span class="lineNum">     425 </span><span class="lineCov">      14832 :     Check(x == y);</span>
<span class="lineNum">     426 </span><span class="lineCov">      14832 :   }</span>
<a name="427"><span class="lineNum">     427 </span>            : </a>
<span class="lineNum">     428 </span>            :   template &lt;int tExponent, int tIntegerBits_a&gt;
<span class="lineNum">     429 </span><span class="lineCov">         12 :   void test_ExactMulByPot(const std::vector&lt;ScalarType&gt;&amp; testvals) {</span>
<span class="lineNum">     430 </span><span class="lineCov">      14844 :     for (auto a : testvals) {</span>
<span class="lineNum">     431 </span>            :       FixedPoint&lt;ScalarType, tIntegerBits_a&gt; aq;
<span class="lineNum">     432 </span><span class="lineCov">      14832 :       aq.raw() = a;</span>
<span class="lineNum">     433 </span><span class="lineCov">      14832 :       test_ExactMulByPot&lt;tExponent, tIntegerBits_a&gt;(aq);</span>
<span class="lineNum">     434 </span>            :     }
<span class="lineNum">     435 </span><span class="lineCov">         12 :   }</span>
<a name="436"><span class="lineNum">     436 </span>            : </a>
<span class="lineNum">     437 </span>            :   // Make the list of test values to test each op against.
<span class="lineNum">     438 </span><span class="lineCov">          2 :   std::vector&lt;ScalarType&gt; MakeTestVals() {</span>
<span class="lineNum">     439 </span><span class="lineCov">          2 :     std::vector&lt;ScalarType&gt; testvals;</span>
<span class="lineNum">     440 </span>            : 
<span class="lineNum">     441 </span><span class="lineCov">         48 :     for (int i = 0; i &lt; kScalarTypeBits - 1; i++) {</span>
<span class="lineNum">     442 </span><span class="lineCov">         46 :       testvals.push_back((1 &lt;&lt; i) - 2);</span>
<span class="lineNum">     443 </span><span class="lineCov">         46 :       testvals.push_back((1 &lt;&lt; i) - 1);</span>
<span class="lineNum">     444 </span><span class="lineCov">         46 :       testvals.push_back((1 &lt;&lt; i));</span>
<span class="lineNum">     445 </span><span class="lineCov">         46 :       testvals.push_back((1 &lt;&lt; i) + 1);</span>
<span class="lineNum">     446 </span><span class="lineCov">         46 :       testvals.push_back((1 &lt;&lt; i) + 2);</span>
<span class="lineNum">     447 </span><span class="lineCov">         46 :       testvals.push_back(-(1 &lt;&lt; i) - 2);</span>
<span class="lineNum">     448 </span><span class="lineCov">         46 :       testvals.push_back(-(1 &lt;&lt; i) - 1);</span>
<span class="lineNum">     449 </span><span class="lineCov">         46 :       testvals.push_back(-(1 &lt;&lt; i));</span>
<span class="lineNum">     450 </span><span class="lineCov">         46 :       testvals.push_back(-(1 &lt;&lt; i) + 1);</span>
<span class="lineNum">     451 </span><span class="lineCov">         46 :       testvals.push_back(-(1 &lt;&lt; i) + 2);</span>
<span class="lineNum">     452 </span>            :     }
<span class="lineNum">     453 </span><span class="lineCov">          2 :     testvals.push_back(std::numeric_limits&lt;ScalarType&gt;::min());</span>
<span class="lineNum">     454 </span><span class="lineCov">          2 :     testvals.push_back(std::numeric_limits&lt;ScalarType&gt;::min() + 1);</span>
<span class="lineNum">     455 </span><span class="lineCov">          2 :     testvals.push_back(std::numeric_limits&lt;ScalarType&gt;::min() + 2);</span>
<span class="lineNum">     456 </span><span class="lineCov">          2 :     testvals.push_back(std::numeric_limits&lt;ScalarType&gt;::max() - 2);</span>
<span class="lineNum">     457 </span><span class="lineCov">          2 :     testvals.push_back(std::numeric_limits&lt;ScalarType&gt;::max() - 1);</span>
<span class="lineNum">     458 </span><span class="lineCov">          2 :     testvals.push_back(std::numeric_limits&lt;ScalarType&gt;::max());</span>
<span class="lineNum">     459 </span>            : 
<span class="lineNum">     460 </span><span class="lineCov">          2 :     std::mt19937 random_engine;</span>
<span class="lineNum">     461 </span>            :     std::uniform_int_distribution&lt;ScalarType&gt; uniform_distribution(
<span class="lineNum">     462 </span><span class="lineCov">          1 :         std::numeric_limits&lt;ScalarType&gt;::min(),</span>
<span class="lineNum">     463 </span><span class="lineCov">          3 :         std::numeric_limits&lt;ScalarType&gt;::max());</span>
<span class="lineNum">     464 </span><span class="lineCov">       2002 :     for (int i = 0; i &lt; 1000; i++) {</span>
<span class="lineNum">     465 </span><span class="lineCov">       2000 :       testvals.push_back(uniform_distribution(random_engine));</span>
<span class="lineNum">     466 </span>            :     }
<span class="lineNum">     467 </span>            : 
<span class="lineNum">     468 </span>            :     // SIMD tests will require the length of testvals to be a multiple
<span class="lineNum">     469 </span>            :     // of SIMD vector size.
<span class="lineNum">     470 </span><span class="lineCov">          2 :     while (testvals.size() % kSimdLanes) {</span>
<span class="lineNum">     471 </span><span class="lineNoCov">          0 :       testvals.push_back(0);</span>
<span class="lineNum">     472 </span>            :     }
<span class="lineNum">     473 </span>            : 
<span class="lineNum">     474 </span><span class="lineCov">          2 :     std::sort(testvals.begin(), testvals.end());</span>
<span class="lineNum">     475 </span><span class="lineCov">          2 :     return testvals;</span>
<a name="476"><span class="lineNum">     476 </span>            :   }</a>
<span class="lineNum">     477 </span>            : 
<span class="lineNum">     478 </span><span class="lineCov">          2 :   void RunTests(const char* msg) {</span>
<span class="lineNum">     479 </span><span class="lineCov">          4 :     const std::vector&lt;ScalarType&gt; testvals = MakeTestVals();</span>
<span class="lineNum">     480 </span>            : 
<span class="lineNum">     481 </span><span class="lineCov">         50 :     for (int s = 0; s &lt; kScalarTypeBits; s++) {</span>
<span class="lineNum">     482 </span><span class="lineCov">         48 :       TestUnaryOp(RoundingDivideByPOTOp(s), testvals);</span>
<span class="lineNum">     483 </span>            :     }
<span class="lineNum">     484 </span>            : 
<span class="lineNum">     485 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;1 - kScalarTypeBits&gt;(),</span>
<span class="lineNum">     486 </span>            :                 testvals);
<span class="lineNum">     487 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;2 - kScalarTypeBits&gt;(),</span>
<span class="lineNum">     488 </span>            :                 testvals);
<span class="lineNum">     489 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;3 - kScalarTypeBits&gt;(),</span>
<span class="lineNum">     490 </span>            :                 testvals);
<span class="lineNum">     491 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;14 - kScalarTypeBits&gt;(),</span>
<span class="lineNum">     492 </span>            :                 testvals);
<span class="lineNum">     493 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;15 - kScalarTypeBits&gt;(),</span>
<span class="lineNum">     494 </span>            :                 testvals);
<span class="lineNum">     495 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;-15&gt;(), testvals);</span>
<span class="lineNum">     496 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;-4&gt;(), testvals);</span>
<span class="lineNum">     497 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;-3&gt;(), testvals);</span>
<span class="lineNum">     498 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;-2&gt;(), testvals);</span>
<span class="lineNum">     499 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;-1&gt;(), testvals);</span>
<span class="lineNum">     500 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;0&gt;(), testvals);</span>
<span class="lineNum">     501 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;1&gt;(), testvals);</span>
<span class="lineNum">     502 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;2&gt;(), testvals);</span>
<span class="lineNum">     503 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;3&gt;(), testvals);</span>
<span class="lineNum">     504 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;4&gt;(), testvals);</span>
<span class="lineNum">     505 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;15&gt;(), testvals);</span>
<span class="lineNum">     506 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;kScalarTypeBits - 15&gt;(),</span>
<span class="lineNum">     507 </span>            :                 testvals);
<span class="lineNum">     508 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;kScalarTypeBits - 14&gt;(),</span>
<span class="lineNum">     509 </span>            :                 testvals);
<span class="lineNum">     510 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;kScalarTypeBits - 3&gt;(),</span>
<span class="lineNum">     511 </span>            :                 testvals);
<span class="lineNum">     512 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;kScalarTypeBits - 2&gt;(),</span>
<span class="lineNum">     513 </span>            :                 testvals);
<span class="lineNum">     514 </span><span class="lineCov">          2 :     TestUnaryOp(SaturatingRoundingMultiplyByPOTOp&lt;kScalarTypeBits - 1&gt;(),</span>
<span class="lineNum">     515 </span>            :                 testvals);
<span class="lineNum">     516 </span>            : 
<span class="lineNum">     517 </span><span class="lineCov">          2 :     TestUnaryOp(ExpOnIntervalBetweenNegativeOneQuarterAnd0ExclOp(), testvals);</span>
<span class="lineNum">     518 </span><span class="lineCov">          2 :     TestUnaryOp(ExpOnNegativeValuesOp&lt;0&gt;(), testvals);</span>
<span class="lineNum">     519 </span><span class="lineCov">          2 :     TestUnaryOp(ExpOnNegativeValuesOp&lt;1&gt;(), testvals);</span>
<span class="lineNum">     520 </span><span class="lineCov">          2 :     TestUnaryOp(ExpOnNegativeValuesOp&lt;2&gt;(), testvals);</span>
<span class="lineNum">     521 </span><span class="lineCov">          2 :     TestUnaryOp(ExpOnNegativeValuesOp&lt;3&gt;(), testvals);</span>
<span class="lineNum">     522 </span><span class="lineCov">          2 :     TestUnaryOp(ExpOnNegativeValuesOp&lt;4&gt;(), testvals);</span>
<span class="lineNum">     523 </span><span class="lineCov">          2 :     TestUnaryOp(ExpOnNegativeValuesOp&lt;5&gt;(), testvals);</span>
<span class="lineNum">     524 </span><span class="lineCov">          2 :     TestUnaryOp(ExpOnNegativeValuesOp&lt;6&gt;(), testvals);</span>
<span class="lineNum">     525 </span>            : 
<span class="lineNum">     526 </span><span class="lineCov">          2 :     TestUnaryOp(OneMinusXOverOnePlusXForXIn01Op(), testvals);</span>
<span class="lineNum">     527 </span><span class="lineCov">          2 :     TestUnaryOp(TanhOp&lt;0&gt;(), testvals);</span>
<span class="lineNum">     528 </span><span class="lineCov">          2 :     TestUnaryOp(TanhOp&lt;1&gt;(), testvals);</span>
<span class="lineNum">     529 </span><span class="lineCov">          2 :     TestUnaryOp(TanhOp&lt;2&gt;(), testvals);</span>
<span class="lineNum">     530 </span><span class="lineCov">          2 :     TestUnaryOp(TanhOp&lt;3&gt;(), testvals);</span>
<span class="lineNum">     531 </span><span class="lineCov">          2 :     TestUnaryOp(TanhOp&lt;4&gt;(), testvals);</span>
<span class="lineNum">     532 </span><span class="lineCov">          2 :     TestUnaryOp(TanhOp&lt;5&gt;(), testvals);</span>
<span class="lineNum">     533 </span><span class="lineCov">          2 :     TestUnaryOp(TanhOp&lt;6&gt;(), testvals);</span>
<span class="lineNum">     534 </span>            : 
<span class="lineNum">     535 </span><span class="lineCov">          2 :     TestUnaryOp(OneOverOnePlusXForXIn01Op(), testvals);</span>
<span class="lineNum">     536 </span><span class="lineCov">          2 :     TestUnaryOp(LogisticOp&lt;0&gt;(), testvals);</span>
<span class="lineNum">     537 </span><span class="lineCov">          2 :     TestUnaryOp(LogisticOp&lt;1&gt;(), testvals);</span>
<span class="lineNum">     538 </span><span class="lineCov">          2 :     TestUnaryOp(LogisticOp&lt;2&gt;(), testvals);</span>
<span class="lineNum">     539 </span><span class="lineCov">          2 :     TestUnaryOp(LogisticOp&lt;3&gt;(), testvals);</span>
<span class="lineNum">     540 </span><span class="lineCov">          2 :     TestUnaryOp(LogisticOp&lt;4&gt;(), testvals);</span>
<span class="lineNum">     541 </span><span class="lineCov">          2 :     TestUnaryOp(LogisticOp&lt;5&gt;(), testvals);</span>
<span class="lineNum">     542 </span><span class="lineCov">          2 :     TestUnaryOp(LogisticOp&lt;6&gt;(), testvals);</span>
<span class="lineNum">     543 </span>            : 
<span class="lineNum">     544 </span><span class="lineCov">       2474 :     for (auto a : testvals) {</span>
<span class="lineNum">     545 </span>            :       FixedPoint&lt;ScalarType, 4&gt; x;
<span class="lineNum">     546 </span><span class="lineCov">       2472 :       x.raw() = a;</span>
<span class="lineNum">     547 </span><span class="lineCov">       2472 :       test_convert(x);</span>
<span class="lineNum">     548 </span>            :     }
<span class="lineNum">     549 </span>            : 
<span class="lineNum">     550 </span><span class="lineCov">          2 :     test_mul&lt;0, 0&gt;(testvals);</span>
<span class="lineNum">     551 </span><span class="lineCov">          2 :     test_mul&lt;0, 1&gt;(testvals);</span>
<span class="lineNum">     552 </span><span class="lineCov">          2 :     test_mul&lt;2, 0&gt;(testvals);</span>
<span class="lineNum">     553 </span><span class="lineCov">          2 :     test_mul&lt;1, 1&gt;(testvals);</span>
<span class="lineNum">     554 </span><span class="lineCov">          2 :     test_mul&lt;4, 4&gt;(testvals);</span>
<span class="lineNum">     555 </span><span class="lineCov">          2 :     test_mul&lt;3, 5&gt;(testvals);</span>
<span class="lineNum">     556 </span><span class="lineCov">          2 :     test_mul&lt;7, 2&gt;(testvals);</span>
<span class="lineNum">     557 </span><span class="lineCov">          2 :     test_mul&lt;kScalarTypeBits / 2 - 1, kScalarTypeBits / 2 - 2&gt;(testvals);</span>
<span class="lineNum">     558 </span>            : 
<span class="lineNum">     559 </span><span class="lineCov">          2 :     test_Rescale&lt;0, 0&gt;(testvals);</span>
<span class="lineNum">     560 </span><span class="lineCov">          2 :     test_Rescale&lt;0, 1&gt;(testvals);</span>
<span class="lineNum">     561 </span><span class="lineCov">          2 :     test_Rescale&lt;2, 0&gt;(testvals);</span>
<span class="lineNum">     562 </span><span class="lineCov">          2 :     test_Rescale&lt;4, 4&gt;(testvals);</span>
<span class="lineNum">     563 </span><span class="lineCov">          2 :     test_Rescale&lt;4, 5&gt;(testvals);</span>
<span class="lineNum">     564 </span><span class="lineCov">          2 :     test_Rescale&lt;6, 3&gt;(testvals);</span>
<span class="lineNum">     565 </span><span class="lineCov">          2 :     test_Rescale&lt;13, 9&gt;(testvals);</span>
<span class="lineNum">     566 </span>            : 
<span class="lineNum">     567 </span><span class="lineCov">          2 :     test_ExactMulByPot&lt;0, 0&gt;(testvals);</span>
<span class="lineNum">     568 </span><span class="lineCov">          2 :     test_ExactMulByPot&lt;0, 4&gt;(testvals);</span>
<span class="lineNum">     569 </span><span class="lineCov">          2 :     test_ExactMulByPot&lt;1, 4&gt;(testvals);</span>
<span class="lineNum">     570 </span><span class="lineCov">          2 :     test_ExactMulByPot&lt;3, 2&gt;(testvals);</span>
<span class="lineNum">     571 </span><span class="lineCov">          2 :     test_ExactMulByPot&lt;-4, 5&gt;(testvals);</span>
<span class="lineNum">     572 </span><span class="lineCov">          2 :     test_ExactMulByPot&lt;-2, 6&gt;(testvals);</span>
<span class="lineNum">     573 </span>            : 
<span class="lineNum">     574 </span><span class="lineCov">          2 :     fprintf(stderr, &quot;PASS (%s)\n&quot;, msg);</span>
<span class="lineNum">     575 </span><span class="lineCov">          2 :   }</span>
<span class="lineNum">     576 </span>            : };
<span class="lineNum">     577 </span>            : 
<span class="lineNum">     578 </span>            : }  // end anonymous namespace
<span class="lineNum">     579 </span>            : 
<a name="580"><span class="lineNum">     580 </span>            : }  // end namespace gemmlowp</a>
<span class="lineNum">     581 </span>            : 
<span class="lineNum">     582 </span><span class="lineCov">          1 : int main() {</span>
<span class="lineNum">     583 </span><span class="lineCov">          1 :   gemmlowp::TestFixedPoint&lt;std::int32_t&gt;().RunTests(&quot;Scalar int32&quot;);</span>
<span class="lineNum">     584 </span><span class="lineCov">          1 :   gemmlowp::TestFixedPoint&lt;std::int16_t&gt;().RunTests(&quot;Scalar int16&quot;);</span>
<span class="lineNum">     585 </span>            : #ifdef GEMMLOWP_SSE4
<span class="lineNum">     586 </span>            :   gemmlowp::TestFixedPoint&lt;__m128i&gt;().RunTests(&quot;SSE4 __m128i = int32x4&quot;);
<span class="lineNum">     587 </span>            :   gemmlowp::TestFixedPoint&lt;gemmlowp::int16x8_m128i&gt;().RunTests(
<span class="lineNum">     588 </span>            :       &quot;SSE4 __m128i = int16x8&quot;);
<span class="lineNum">     589 </span>            : #endif
<span class="lineNum">     590 </span>            : #ifdef GEMMLOWP_NEON
<span class="lineNum">     591 </span>            :   gemmlowp::TestFixedPoint&lt;int32x4_t&gt;().RunTests(&quot;NEON int32x4_t&quot;);
<span class="lineNum">     592 </span>            :   gemmlowp::TestFixedPoint&lt;int16x8_t&gt;().RunTests(&quot;NEON int16x8_t&quot;);
<span class="lineNum">     593 </span>            : #endif
<span class="lineNum">     594 </span>            : #ifdef GEMMLOWP_MSA
<span class="lineNum">     595 </span>            :   gemmlowp::TestFixedPoint&lt;v4i32&gt;().RunTests(&quot;MSA v4i32&quot;);
<span class="lineNum">     596 </span>            :   gemmlowp::TestFixedPoint&lt;v8i16&gt;().RunTests(&quot;MSA v8i16&quot;);
<span class="lineNum">     597 </span>            : #endif
<span class="lineNum">     598 </span>            : #ifdef GEMMLOWP_AVX2
<span class="lineNum">     599 </span>            :   gemmlowp::TestFixedPoint&lt;__m256i&gt;().RunTests(&quot;AVX __m256i&quot;);
<span class="lineNum">     600 </span>            :   gemmlowp::TestFixedPoint&lt;gemmlowp::int16x16_m256i&gt;().RunTests(
<a name="601"><span class="lineNum">     601 </span>            :       &quot;AVX2 __m256i = int16x16&quot;);</a>
<span class="lineNum">     602 </span>            : #endif
<span class="lineNum">     603 </span><span class="lineCov">          4 : }</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
